/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.univnantes.alma.arbres;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.NoSuchElementException;

/**
 *
 * @author judu
 */
class ArbreLAIteratorBFS<T> implements Iterator<Noeud<T>> {

    private LinkedList<NoeudLA<T>> enVisite;
    

    public ArbreLAIteratorBFS(NoeudLA<T> current) {
        this.enVisite = new LinkedList<NoeudLA<T>>();
        this.enVisite.addLast(current);
    }

    private void setUpNext(NoeudLA<T> current){
        this.enVisite.addAll(current.getFils());
    }

    public boolean hasNext() {
        return !(this.enVisite.isEmpty());
    }

    public void remove() {
        throw new UnsupportedOperationException("Pas possible");
    }

    public Noeud<T> next() {
        if(!this.hasNext()) throw new NoSuchElementException("Terminus de l'arbre, vérifiez en sortant que vous n'oubliez aucun bagage.");
        NoeudLA<T> current = this.enVisite.pollFirst();
        this.setUpNext(current);
        return current.autoCast();
    }

}
